package com.example.dllo.exe.fenlei.danpin;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.exe.R;
import com.example.dllo.exe.bean.DanPinPinJieBean;
import com.example.dllo.exe.fengzhuang.NetTool;
import com.example.dllo.exe.fenlei.xuanlishenqi.XuLiShenQiRVAdapter;

/**
 * code is far away from bug with the animal protecting
 * <p/>
 * ┏┓　　　┏┓
 * ┏┛┻━━━┛┻┓
 * ┃　　　　　　　┃
 * ┃　　　━　　　┃
 * ┃　┳┛　┗┳　┃
 * ┃　　　　　　　┃
 * ┃　　　┻　　　┃
 * ┃　　　　　　　┃
 * ┗━┓　　　┏━┛
 * 　　┃　　　┃神兽保佑
 * 　　┃　　　┃永无BUG！  凯哥 祝你一路顺风
 * 　　┃　　　┗━━━┓
 * 　　┃　　　　　　　┣┓
 * 　　┃　　　　　　　┏┛
 * 　　┗┓┓┏━┳┓┏┛
 * 　　　┃┫┫　┃┫┫
 * 　　　┗┻┛　┗┻┛
 */
public class DanPinPinJieAdapter extends RecyclerView.Adapter<DanPinPinJieAdapter.MyViewHolder>{
    private Context context;
    private DanPinPinJieBean danPinPinJieBean;


    public void setDanPinPinJieBean(DanPinPinJieBean danPinPinJieBean) {
        this.danPinPinJieBean = danPinPinJieBean;
        notifyDataSetChanged();
    }

    public DanPinPinJieAdapter(Context context) {
        this.context = context;
    }

    @Override
    public DanPinPinJieAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view= LayoutInflater.from(context).inflate(R.layout.danpinpinjiesecondlayout,parent,false);
        MyViewHolder viewHolder=new MyViewHolder(view);

        return viewHolder;
    }

    @Override
    public void onBindViewHolder(DanPinPinJieAdapter.MyViewHolder holder, int position) {
        holder.textViewprice.setText(danPinPinJieBean.getData().getItems().get(position).getPrice());
        holder.textViewname.setText(danPinPinJieBean.getData().getItems().get(position).getName());

        holder.textViewlikescount.setText(danPinPinJieBean.getData().getItems().get(position).getFavorites_count()+"");
        NetTool netTool=new NetTool();
        netTool.getImage(danPinPinJieBean.getData().getItems().get(position).getCover_image_url(),holder.imageViewcoverimage);
    }

    @Override
    public int getItemCount() {
        return danPinPinJieBean!=null?danPinPinJieBean.getData().getItems().size():0;
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {
        TextView textViewprice;
        TextView textViewlikescount;
        TextView textViewname;
        ImageView imageViewcoverimage;
        public MyViewHolder(View itemView) {
            super(itemView);
            textViewprice= (TextView) itemView.findViewById(R.id.Price_PinJie);
            textViewlikescount= (TextView) itemView.findViewById(R.id.Favorites_PinJie);
            textViewname= (TextView) itemView.findViewById(R.id.Name_PinJie);
            imageViewcoverimage= (ImageView) itemView.findViewById(R.id.Image_PinJie);
        }
    }
}
